package br.com.amigooo.controller;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

import br.com.amigooo.Session.UserSession;
import br.com.amigooo.model.Establishment;
import br.com.amigooo.model.Item;
import br.com.amigooo.repository.EstablishmentImpl;
import br.com.amigooo.repository.ItemImpl;
import br.com.amigooo.util.Utils;
import br.com.caelum.vraptor.Get;
import br.com.caelum.vraptor.Path;
import br.com.caelum.vraptor.Post;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;
import static br.com.caelum.vraptor.view.Results.json; 

@Resource
public class MenuController {

	private Result result;
    private UserSession userSession;
    private ItemImpl itemImpl;
	
    public MenuController(Result result, UserSession userSession) {
        this.result = result;
        this.userSession = userSession;
        this.itemImpl = new ItemImpl();
    }

    /*
     * XXX: MÉTODOS DE VISUALIZAÇÕES
     */
	@Path("/drinks")
	public void viewDrink() {
		List<Item> itens = null;
		try{
			itens = this.itemImpl.getItemByCompany(1, userSession.getUser().getEstablishment().getId());
			
			if(itens.size() > 0){
				result.include("drinks", itens);
			}else{
				result.include("drinks", null);
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao listar as bebidas.", Utils.ERROR));
		}
	}
	
	@Path("/meals")
	public void viewMeal() {
		List<Item> itens = null;
		try{
			itens = this.itemImpl.getItemByCompany(2, userSession.getUser().getEstablishment().getId());
			
			if(itens.size() > 0){
				result.include("meals", itens);
			}else{
				result.include("meals", null);
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao listar as refeições.", Utils.ERROR));
		}
	}
	
	@Path("/snacks")
	public void viewSnack() {
		List<Item> itens = null;
		try{
			itens = this.itemImpl.getItemByCompany(3, userSession.getUser().getEstablishment().getId());
			
			if(itens.size() > 0){
				result.include("snacks", itens);
			}else{
				result.include("snacks", null);
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao listar os lanches.", Utils.ERROR));
		}
	}
	
	@Path("/specials")
	public void viewSpecial() {
		List<Item> itens = null;
		try{
			itens = this.itemImpl.getItemByCompany(4, userSession.getUser().getEstablishment().getId());
			
			if(itens.size() > 0){
				result.include("specials", itens);
			}else{
				result.include("specials", null);
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao listar os especiais.", Utils.ERROR));
		}
	}
	
	@Path("/sales")
	public void viewSale() {
		List<Item> itens = null;
		try{
			itens = this.itemImpl.getItemByCompany(5, userSession.getUser().getEstablishment().getId());
			
			if(itens.size() > 0){
				result.include("sales", itens);
			}else{
				result.include("sales", null);
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao listar as promoções.", Utils.ERROR));
		}
	}
	
	@Path("/others")
	public void viewOther() {
		List<Item> itens = null;
		try{
			itens = this.itemImpl.getItemByCompany(6, userSession.getUser().getEstablishment().getId());
			
			if(itens.size() > 0){
				result.include("others", itens);
			}else{
				result.include("others", null);
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao listar os itens.", Utils.ERROR));
		}
	}
    /*
     * XXX: FIM DOS MÉTODOS DE VISUALIZAÇÕES
     */
	
	/*
	 * XXX: MÉTODOS DE CRIAÇÃO 
	 */
    
	@Post
	@Path("/drinks/create")
	public void createDrink(Item item){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		item.setType(1);
		item.setEstablishment(userSession.getUser().getEstablishment());
		
		try{
			this.itemImpl.save(item);
			
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			Set<Item> sItem = establishment.getItem();
			sItem.add(item);
			establishmentImpl.update(establishment);
			
			result.include("result", Utils.message("Bebida adicionada.", Utils.SUCCESS)).redirectTo(this.getClass()).viewDrink();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao adicionar a bebida.", Utils.ERROR)).redirectTo(this.getClass()).viewDrink();
		}
	}
	
	@Post
	
	@Path("/meals/create")
	public void createMeal(Item item){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		item.setType(2);
		item.setEstablishment(userSession.getUser().getEstablishment());
		
		try{
			this.itemImpl.save(item);
			
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			Set<Item> sItem = establishment.getItem();
			sItem.add(item);
			establishmentImpl.update(establishment);
			
			result.include("result", Utils.message("Refeição adicionada.", Utils.SUCCESS)).redirectTo(this.getClass()).viewMeal();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao adicionar a refeição.", Utils.ERROR)).redirectTo(this.getClass()).viewMeal();
		}
	}
	
	@Post
	
	@Path("/snacks/create")
	public void createSnack(Item item){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		item.setType(3);
		item.setEstablishment(userSession.getUser().getEstablishment());
		
		try{
			this.itemImpl.save(item);
			
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			Set<Item> sItem = establishment.getItem();
			sItem.add(item);
			establishmentImpl.update(establishment);
			
			result.include("result", Utils.message("Lanche adicionado.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSnack();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao adicionar o lanche.", Utils.ERROR)).redirectTo(this.getClass()).viewSnack();
		}
	}
	
	@Post
	
	@Path("/specials/create")
	public void createSpecial(Item item){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		item.setType(4);
		item.setEstablishment(userSession.getUser().getEstablishment());
		
		try{
			this.itemImpl.save(item);
			
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			Set<Item> sItem = establishment.getItem();
			sItem.add(item);
			establishmentImpl.update(establishment);
			
			result.include("result", Utils.message("Especial adicionado.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSpecial();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao adicionar o especial.", Utils.ERROR)).redirectTo(this.getClass()).viewSpecial();
		}
	}
	
	@Post
	
	@Path("/sales/create")
	public void createSale(Item item){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		item.setType(5);
		item.setEstablishment(userSession.getUser().getEstablishment());
		
		try{
			this.itemImpl.save(item);
			
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			Set<Item> sItem = establishment.getItem();
			sItem.add(item);
			establishmentImpl.update(establishment);
			
			result.include("result", Utils.message("Promoção adicionada.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSale();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao adicionar a promoção.", Utils.ERROR)).redirectTo(this.getClass()).viewSale();
		}
	}
	
	@Post
	
	@Path("/others/create")
	public void createOther(Item item){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		item.setType(6);
		item.setEstablishment(userSession.getUser().getEstablishment());
		
		try{
			this.itemImpl.save(item);
			
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			Set<Item> sItem = establishment.getItem();
			sItem.add(item);
			establishmentImpl.update(establishment);
			
			result.include("result", Utils.message("Item adicionado.", Utils.SUCCESS)).redirectTo(this.getClass()).viewOther();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao adicionar o item.", Utils.ERROR)).redirectTo(this.getClass()).viewOther();
		}
	}
	/*
	 * XXX: FIM DOS MÉTODOS DE CRIAÇÃO 
	 */
	
	/*
	 * XXX: MÉTODOS DE EDIÇÃO 
	 */
	@Path("/drinks/{item.id}/edit")
	@Get
	public void editDrinks(Item item){
		try{
			Item it = this.itemImpl.getItem(item.getId());

			if(it != null && it.getId() != null){
				result.use(json()).from(it).include("establishment").serialize();
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			result.include("error", Utils.message("Ocorreu um erro ao editar a bebida.", Utils.ERROR)).redirectTo(this.getClass()).viewDrink();
		}
	}
	
	
	@Path("/meals/{item.id}/edit")
	@Get
	public void editMeals(Item item){
		try{
			Item it = this.itemImpl.getItem(item.getId());
			
			if(it != null && it.getId() != null){
				result.use(json()).from(it).include("establishment").serialize();
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			result.include("error", Utils.message("Ocorreu um erro ao editar a refeição.", Utils.ERROR)).redirectTo(this.getClass()).viewMeal();
		}
	}
	
	
	@Path("/snacks/{item.id}/edit")
	@Get
	public void editSnacks(Item item){
		try{
			Item it = this.itemImpl.getItem(item.getId());
			
			if(it != null && it.getId() != null){
				result.use(json()).from(it).include("establishment").serialize();
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			result.include("error", Utils.message("Ocorreu um erro ao editar o lanche.", Utils.ERROR)).redirectTo(this.getClass()).viewSnack();
		}
	}
	
	
	@Path("/specials/{item.id}/edit")
	@Get
	public void editSpecials(Item item){
		try{
			Item it = this.itemImpl.getItem(item.getId());
			
			if(it != null && it.getId() != null){
				result.use(json()).from(it).include("establishment").serialize();
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			result.include("error", Utils.message("Ocorreu um erro ao editar o especial.", Utils.ERROR)).redirectTo(this.getClass()).viewSpecial();
		}
	}
	
	
	@Path("/sales/{item.id}/edit")
	@Get
	public void editSales(Item item){
		try{
			Item it = this.itemImpl.getItem(item.getId());
			
			if(it != null && it.getId() != null){
				result.use(json()).from(it).include("establishment").serialize();
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			result.include("error", Utils.message("Ocorreu um erro ao editar a promoção.", Utils.ERROR)).redirectTo(this.getClass()).viewSale();
		}
	}
	
	
	@Path("/others/{item.id}/edit")
	@Get
	public void editOthers(Item item){
		try{
			Item it = this.itemImpl.getItem(item.getId());
			
			if(it != null && it.getId() != null){
				result.use(json()).from(it).include("establishment").serialize();
			}
		}catch(RuntimeException e){
			e.printStackTrace();
			result.include("error", Utils.message("Ocorreu um erro ao editar o item.", Utils.ERROR)).redirectTo(this.getClass()).viewOther();
		}
	}
	/*
	 * XXX: FIM DOS MÉTODOS DE EDIÇÃO 
	 */
	
	/*
	 * XXX: MÉTODOS DE ATUALIZAÇÃO 
	 */
	
	@Post
	@Path("/drinks/update")
	public void updateDrink(Item itemed){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;

		try{
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			itemed.setEstablishment(establishment);
			
			this.itemImpl.update(itemed);

			result.include("result", Utils.message("Bebida atualizada.", Utils.SUCCESS)).redirectTo(this.getClass()).viewDrink();
		}catch(RuntimeException e){
			e.printStackTrace();

			result.include("error", Utils.message("Ocorreu um erro ao atualizar a bebida.", Utils.ERROR)).redirectTo(this.getClass()).viewDrink();
		}
	}
	
	
	@Post
	@Path("/meals/update")
	public void updateMeal(Item itemed){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		try{
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			itemed.setEstablishment(establishment);
			
			this.itemImpl.update(itemed);
			
			result.include("result", Utils.message("Bebida atualizada.", Utils.SUCCESS)).redirectTo(this.getClass()).viewMeal();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao atualizar a bebida.", Utils.ERROR)).redirectTo(this.getClass()).viewMeal();
		}
	}
	
	
	@Post
	@Path("/snacks/update")
	public void updateSnack(Item itemed){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		try{
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			itemed.setEstablishment(establishment);
			
			this.itemImpl.update(itemed);
			
			result.include("result", Utils.message("Lanche atualizado.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSnack();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao atualizar o lanche.", Utils.ERROR)).redirectTo(this.getClass()).viewSnack();
		}
	}
	
	
	@Post
	@Path("/specials/update")
	public void updateSpecial(Item itemed){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		try{
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			itemed.setEstablishment(establishment);
			
			this.itemImpl.update(itemed);
			
			result.include("result", Utils.message("Especial atualizado.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSpecial();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao atualizar o especial.", Utils.ERROR)).redirectTo(this.getClass()).viewSpecial();
		}
	}
	
	
	@Post
	@Path("/sales/update")
	public void updateSale(Item itemed){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		try{
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			itemed.setEstablishment(establishment);
			
			this.itemImpl.update(itemed);
			
			result.include("result", Utils.message("Promoção atualizada.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSale();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao atualizar a promoção.", Utils.ERROR)).redirectTo(this.getClass()).viewSale();
		}
	}
	
	
	@Post
	@Path("/others/update")
	public void updateOther(Item itemed){
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = null;
		
		try{
			establishment = establishmentImpl.getEstablishment(userSession.getUser().getEstablishment().getId());
			itemed.setEstablishment(establishment);
			
			this.itemImpl.update(itemed);
			
			result.include("result", Utils.message("Item atualizado.", Utils.SUCCESS)).redirectTo(this.getClass()).viewOther();
		}catch(RuntimeException e){
			e.printStackTrace();
			
			result.include("error", Utils.message("Ocorreu um erro ao atualizar o item.", Utils.ERROR)).redirectTo(this.getClass()).viewOther();
		}
	}
	/*
	 * XXX: FIM DOS MÉTODOS DE ATUALIZAÇÃO 
	 */
	
	/*
	 * XXX: MÉTODOS DE EXCLUSÃO 
	 */
	
	@Path("/drinks/{item.id}/delete")
	public void deleteDrink(Item item){
		List<Item> itens = null;
		Item item_aux = null;
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = new Establishment();
		
		if(item != null && item.getId() != null){
			try{
				itens = this.itemImpl.getItemByCompany(1, userSession.getUser().getEstablishment().getId());
				
				Set<Item> it = new HashSet<Item>(itens);
				
				for(Item i : it){
					if(i.getId() == item.getId()){
						item_aux = i;
					}
				}
				
				it.remove(item_aux);
				
				item_aux = this.itemImpl.getItem(item.getId());
				
				establishment = establishmentImpl.getEstablishment(item_aux.getEstablishment().getId());
				establishment.setItem(it);
				
				establishmentImpl.update(establishment);
				
				this.itemImpl.remove(item);
				
				result.include("result", Utils.message("Bebida removida.", Utils.SUCCESS)).redirectTo(this.getClass()).viewDrink();
			}catch(RuntimeException e){
				e.printStackTrace();
				result.include("error", Utils.message("Ocorreu um erro ao remover a bebida.", Utils.ERROR)).redirectTo(this.getClass()).viewDrink();
			}
		}
	}
	
	
	@Path("/meals/{item.id}/delete")
	public void deleteMeal(Item item){
		List<Item> itens = null;
		Item item_aux = null;
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = new Establishment();
		
		if(item != null && item.getId() != null){
			try{
				itens = this.itemImpl.getItemByCompany(2, userSession.getUser().getEstablishment().getId());
				
				Set<Item> it = new HashSet<Item>(itens);
				
				for(Item i : it){
					if(i.getId() == item.getId()){
						item_aux = i;
					}
				}
				
				it.remove(item_aux);
				
				item_aux = this.itemImpl.getItem(item.getId());
				
				establishment = establishmentImpl.getEstablishment(item_aux.getEstablishment().getId());
				establishment.setItem(it);
				
				establishmentImpl.update(establishment);
				
				this.itemImpl.remove(item);
				
				result.include("result", Utils.message("Bebida removida.", Utils.SUCCESS)).redirectTo(this.getClass()).viewMeal();
			}catch(RuntimeException e){
				e.printStackTrace();
				result.include("error", Utils.message("Ocorreu um erro ao remover a bebida.", Utils.ERROR)).redirectTo(this.getClass()).viewMeal();
			}
		}
	}
	
	
	@Path("/snacks/{item.id}/delete")
	public void deleteSnack(Item item){
		List<Item> itens = null;
		Item item_aux = null;
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = new Establishment();
		
		if(item != null && item.getId() != null){
			try{
				itens = this.itemImpl.getItemByCompany(3, userSession.getUser().getEstablishment().getId());
				
				Set<Item> it = new HashSet<Item>(itens);
				
				for(Item i : it){
					if(i.getId() == item.getId()){
						item_aux = i;
					}
				}
				
				it.remove(item_aux);
				
				item_aux = this.itemImpl.getItem(item.getId());
				
				establishment = establishmentImpl.getEstablishment(item_aux.getEstablishment().getId());
				establishment.setItem(it);
				
				establishmentImpl.update(establishment);
				
				this.itemImpl.remove(item);
				
				result.include("result", Utils.message("Lanche removido.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSnack();
			}catch(RuntimeException e){
				e.printStackTrace();
				result.include("error", Utils.message("Ocorreu um erro ao remover o lanche.", Utils.ERROR)).redirectTo(this.getClass()).viewSnack();
			}
		}
	}
	
	
	@Path("/specials/{item.id}/delete")
	public void deleteSpecial(Item item){
		List<Item> itens = null;
		Item item_aux = null;
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = new Establishment();
		
		if(item != null && item.getId() != null){
			try{
				itens = this.itemImpl.getItemByCompany(4, userSession.getUser().getEstablishment().getId());
				
				Set<Item> it = new HashSet<Item>(itens);
				
				for(Item i : it){
					if(i.getId() == item.getId()){
						item_aux = i;
					}
				}
				
				it.remove(item_aux);
				
				item_aux = this.itemImpl.getItem(item.getId());
				
				establishment = establishmentImpl.getEstablishment(item_aux.getEstablishment().getId());
				establishment.setItem(it);
				
				establishmentImpl.update(establishment);
				
				this.itemImpl.remove(item);
				
				result.include("result", Utils.message("Especial removido.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSpecial();
			}catch(RuntimeException e){
				e.printStackTrace();
				result.include("error", Utils.message("Ocorreu um erro ao remover o especial.", Utils.ERROR)).redirectTo(this.getClass()).viewSpecial();
			}
		}
	}
	
	
	@Path("/sales/{item.id}/delete")
	public void deleteSale(Item item){
		List<Item> itens = null;
		Item item_aux = null;
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = new Establishment();
		
		if(item != null && item.getId() != null){
			try{
				itens = this.itemImpl.getItemByCompany(5, userSession.getUser().getEstablishment().getId());
				
				Set<Item> it = new HashSet<Item>(itens);
				
				for(Item i : it){
					if(i.getId() == item.getId()){
						item_aux = i;
					}
				}
				
				it.remove(item_aux);
				
				item_aux = this.itemImpl.getItem(item.getId());
				
				establishment = establishmentImpl.getEstablishment(item_aux.getEstablishment().getId());
				establishment.setItem(it);
				
				establishmentImpl.update(establishment);
				
				this.itemImpl.remove(item);
				
				result.include("result", Utils.message("Promoção removida.", Utils.SUCCESS)).redirectTo(this.getClass()).viewSale();
			}catch(RuntimeException e){
				e.printStackTrace();
				result.include("error", Utils.message("Ocorreu um erro ao remover a promoção.", Utils.ERROR)).redirectTo(this.getClass()).viewSale();
			}
		}
	}
	
	
	@Path("/others/{item.id}/delete")
	public void deleteOther(Item item){
		List<Item> itens = null;
		Item item_aux = null;
		EstablishmentImpl establishmentImpl = new EstablishmentImpl();
		Establishment establishment = new Establishment();
		
		if(item != null && item.getId() != null){
			try{
				itens = this.itemImpl.getItemByCompany(6, userSession.getUser().getEstablishment().getId());
				
				Set<Item> it = new HashSet<Item>(itens);
				
				for(Item i : it){
					if(i.getId() == item.getId()){
						item_aux = i;
					}
				}
				
				it.remove(item_aux);
				
				item_aux = this.itemImpl.getItem(item.getId());
				
				establishment = establishmentImpl.getEstablishment(item_aux.getEstablishment().getId());
				establishment.setItem(it);
				
				establishmentImpl.update(establishment);
				
				this.itemImpl.remove(item);
				
				result.include("result", Utils.message("Item removido.", Utils.SUCCESS)).redirectTo(this.getClass()).viewOther();
			}catch(RuntimeException e){
				e.printStackTrace();
				result.include("error", Utils.message("Ocorreu um erro ao remover o item.", Utils.ERROR)).redirectTo(this.getClass()).viewOther();
			}
		}
	}
	/*
	 * XXX: FIM DOS MÉTODOS DE EXCLUSÃO 
	 */
}